const mongoose = require("mongoose");
const { Schema } = mongoose;

// 商品参数子文档 Schema
const ArgumentSchema = new Schema({
  title: {
    type: String,
  },
  value: {
    type: String,
  },
});

// 商品类型子文档 Schema
const TypeSchema = new Schema({
  photo: {
    type: String,
    required: true,
  },
  kind: {
    type: String,
    required: true,
  },
  price: {
    type: String,
    required: true,
  },
});

// 商品子文档 Schema
const ProductSchema = new Schema({
  name: {
    type: String,
    required: true,
  },
  photos: {
    type: [String],
    required: true,
  },
  description: {
    type: String,
    required: true,
  },
  tags: {
    type: [String],
    required: true,
  },
  arguments: [ArgumentSchema],
  types: [TypeSchema],
  inventory: {
    type: Number,
    required: true,
  },
  status: {
    type: String,
    required: true,
  },
  freight: {
    type: String,
    required: true,
  },
  afterSale: {
    type: String,
    required: true,
  },
  createdAt: {
    type: Date,
    default: Date.now,
  },
});

// 商店 Schema
const ShopSchema = new Schema(
  {
    category: {
      type: String,
      required: true,
    },
    products: [ProductSchema],
  },
  { versionKey: false }
);

module.exports = mongoose.model("Shop", ShopSchema);
